import type { Rule } from 'ant-design-vue/es/form'
export const validatePhone = async (_rule: Rule, value: string) => {
  const phoneRegex = /^09[0-9]{8}$/
  if (!value) {
    return Promise.reject('請輸入您的手機號碼！')
  }
  if (!phoneRegex.test(value)) {
    return Promise.reject('請輸入一個有效的手機號碼！')
  } else {
    return Promise.resolve()
  }
}

export const validateEmail = async (_rule: Rule, value: string) => {
  const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
  if (!value) {
    return Promise.reject('請輸入您的電子郵件地址！')
  }
  if (!emailRegex.test(value)) {
    return Promise.reject('請輸入一個有效的電子郵件地址！')
  } else {
    return Promise.resolve()
  }
}
